package com.repair.admin.worker.service.impl;

import com.repair.admin.worker.service.AdminWorkerService;
import com.repair.api.worker.request.WorkerQueryPageRequest;
import com.repair.api.worker.request.param.WorkerQueryParam;
import com.repair.api.worker.response.data.WorkerInfo;
import com.repair.api.worker.service.WorkerFacadeService;
import com.repair.base.exception.BizErrorCode;
import com.repair.base.exception.BizException;
import com.repair.base.response.PageResponse;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author zq
 * @version 1.0
 * @create 2024-10-02 22:46
 * @since jdk1.8
 */
@Service
public class AdminWorkerImpl implements AdminWorkerService {
    @DubboReference
    private WorkerFacadeService workerFacadeService;
    @Override
    public List<WorkerInfo> getAllWorkers(WorkerQueryParam workerQueryParam) {
        WorkerQueryPageRequest<WorkerQueryParam> request = new WorkerQueryPageRequest<>();
        request.setData(workerQueryParam);
        request.setCurrentPage(workerQueryParam.getCurrentPage());
        request.setPageSize(workerQueryParam.getPageSize());
        PageResponse<WorkerInfo> allWorkers = workerFacadeService.getAllWorkers(request);
        if (!allWorkers.getSuccess()){
            throw new BizException(BizErrorCode.REMOTE_CALL_RESPONSE_IS_FAILED);
        }
        return allWorkers.getData();
    }
}
